'''
Description: 
Author: Zilu
Date: 2021-11-18 10:41:08
Version: 
LastEditTime: 2021-11-18 11:30:51
LastEditors: Zilu
'''

# 使用 flask web框架
from flask import Flask
from flask import request

app = Flask(__name__)

# Flask通过Python的装饰器在内部自动地把URL和函数给关联起来
@app.route('/', methods=['GET', 'POST'])
def home():
    return '<h1>Home</h1>'

@app.route('/signin', methods=['GET'])
def signin_form():
    return '''
        <form action="/signin" method="post">
        <p><input name="username"></p>
        <p><input name="password" type="password"></p>
        <p><button type="submit">Sign In</button></p>
        </form>
    '''

@app.route('/signin', methods=['POST'])
def signin():
    # 需要从request对象读取表单内容
    # Flask通过request.form['name']来获取表单的内容
    if request.form['username']=='admin' and request.form['password']=='password':
        return '<h3>Hello, admin!</h3>'
    return '<h3>Bad username or password</h3>'

if __name__ == '__main__':
    app.run()




